<?php
header("Content-Type:text/html;charset=gbk");
require '../../packages/connect_database.php';
mysql_select_db("auction");
$title = $_GET["title"];
$file = array();
for($i = 0;$i < 6;$i++)
	$file[$i] = $_FILES["file" . ($i + 1)]["name"];
$car_info = $_POST["auction_info"];
$i = 1;
$data = "";
for(;$i <= 8;$i++) {
	$query = mysql_query("SELECT * FROM auction WHERE number = {$i}");
	if(mysql_num_rows($query) == 0)
		break;
}
if($i == 9) {
	$data = "INSERT INTO waiting VALUES('{$title}','{$_COOKIE["name"]}','{$_COOKIE["phone"]}',";
	for($j = 0;$j < 6;$j++)
		$data .= "'{$file[$j]}',";
	$data .= "'{$car_info}')";
} else {
	$data = "INSERT INTO auction VALUES('{$title}','{$_COOKIE["name"]}','{$_COOKIE["phone"]}',";
	for($j = 0;$j < 6;$j++)
		$data .= "'{$file[$j]}',";
	$data .= "'{$car_info}',0,'','',{$i})";
}
mysql_query($data) or die(mysql_error());
if(!is_dir("../../img/" . $_COOKIE["phone"]))
	mkdir("../../img/" . $_COOKIE["phone"],0744,true);
for($i = 0;$i < 6;$i++)
	move_uploaded_file($_FILES["file" . ($i + 1)]["tmp_name"],"../../img/{$_COOKIE["phone"]}/{$file[$i]}");
clearstatcache();
echo "<script language='javascript'>location = 'waiting_mobile.php';</script>";
